<template>
  <div class="page_background_color">
    <div class="header_area">
      <div class="back_area" @click="toBack">
        <img src="../img/back.png" />
        <p>返回</p>
      </div>
      <div class="page_title">药事指导</div>
      <div class="to_home_area" @click="toHome">
        <img src="../img/首页.png" />
        <p>首页</p>
      </div>
    </div>
    <div class="content_area">
      <div class="menu_area">
        <div
          class="menu_item"
          v-for="item in data"
          :key="item.id"
          v-bind:class="{ active: choosed == item.id }"
          @click="chooseFunction(item.id, item.name)"
        >
          <img :src="choosed == item.id ? item.imgUrl : item.activeImgUrl" />
          <div>
            {{ item.title }}
          </div>
        </div>
      </div>
      <transition name="fade_slide">
        <component :is="component" :kind="kind" :data="data" />
      </transition>
    </div>
  </div>
</template>

<script>
//问题1：阴历日期
//问题2：部分本地图片无法显示
import { reactive, toRefs } from 'vue'
import { useRouter } from 'vue-router'
import buyMedicineServe from './buyMedicineServe/index'
import medicineGuides from './medicineGuides/index'
import heathSelfServe from './heathSelfServe/index'
import selfDocument from './selfDocument/index'

import medicineGuideActive from '../img/medicineGuideActive.png'
import medicineGuide from '../img/medicineGuide.png'
import buyMedicineActive from '../img/buyMedicineActive.png'
import buyMedicine from '../img/buyMedicine.png'
import documentActive from '../img/documentActive.png'
import document from '../img/document.png'
import menuActive from '../img/menuActive.png'
import menu from '../img/menu.png'
export default {
  components: {
    buyMedicineServe,
    medicineGuides,
    heathSelfServe,
    selfDocument,
  },
  setup() {
    let router = useRouter()
    let state = reactive({
      data: [
        {
          id: 1,
          name: 'medicine-guides',
          imgUrl: medicineGuideActive,
          activeImgUrl: medicineGuide,
          title: '药械指导',
          choose: true,
          content: [
            {
              id: 1,
              name: '社区指导',
              path: '',
              imgUrl: '../img/社区指导.png',
            },
            {
              id: 2,
              name: '用药用械指导',
              path: '',
              imgUrl: '../img/店铺.png',
            },
            {
              id: 3,
              name: '电话指导',
              path: '',
              imgUrl: '../img/电话指导.png',
            },
            {
              id: 4,
              name: '医疗器械使用指导',
              path: '',
              imgUrl: '../img/医疗器械校准.png',
            },
            {
              id: 5,
              name: '网络咨询',
              path: '',
              imgUrl: '../img/线上指导.png',
            },
          ],
        },
        {
          id: 2,
          name: 'buy-medicine-serve',
          imgUrl: buyMedicineActive,
          activeImgUrl: buyMedicine,
          title: '购药服务',
          choose: false,
        },
        {
          id: 3,
          name: 'self-document',
          imgUrl: documentActive,
          activeImgUrl: document,
          title: '个人药历档案',
          choose: false,
          content: [
            {
              id: 1,
              name: '个人药历',
              path: '',
              imgUrl: '../img/个人药历.png',
            },
            {
              id: 2,
              name: '药物整理',
              path: '',
              imgUrl: '../img/药物整理.png',
            },
            {
              id: 3,
              name: '不良反应上报',
              path: '',
              imgUrl: '../img/不良反应.png',
            },
            {
              id: 4,
              name: '慢病档案',
              path: '',
              imgUrl: '../img/国家药品查询.png',
            },
            {
              id: 5,
              name: '顾客用药随访',
              path: '',
              imgUrl: '../img/店铺.png',
            },
          ],
        },
        {
          id: 4,
          name: 'heath-self-serve',
          imgUrl: menuActive,
          activeImgUrl: menu,
          title: '健康自助',
          choose: false,
          content: [
            {
              id: 1,
              name: '店内药品查询',
              path: '',
              imgUrl: '../img/店内药品查询.png',
            },
            {
              id: 2,
              name: '国家药瓶查询',
              path: '',
              imgUrl: '../img/国家药品查询.png',
            },
            {
              id: 3,
              name: '健康测量',
              path: '',
              imgUrl: '../img/健康测量.png',
            },
            {
              id: 4,
              name: '自助清创',
              path: '',
              imgUrl: '../img/自助清创.png',
            },
            {
              id: 5,
              name: '医药书刊查询',
              path: '',
              imgUrl: '../img/个人药历.png',
            },
          ],
        },
      ],
      choosed: 1,
      kind: 0,
      component: 'medicine-guides',
    })
    let chooseFunction = (id, name) => {
      state.choosed = id
      state.component = name
      state.data[id - 1].choose = true
      for (let i = 0; i < state.data.length; i++)
        if (i != id - 1) {
          // console.log(state.data)
          if (state.data[i].imgUrl.includes('_1') == false) {
            state.data[i].choose = false
          }
        }
      toDetail(id)
    }
    let toDetail = (id) => {
      state.kind = id - 1
    }
    let toHome = () => {
      router.push({
        path: '/home',
      })
    }
    let toBack = () => {
      router.back()
    }
    return {
      ...toRefs(state),
      chooseFunction,
      toDetail,
      toHome,
      toBack,
    }
  },
}
</script>

<style lang="less" scoped>
* {
  padding: 0;
  margin: 0;
}
.page_background_color {
  background-color: #f1f8ff;
  padding-bottom: 200px;
}
.header_area {
  height: 142px;
  display: flex;
  padding-left: 55px;
  padding-right: 52px;
  justify-content: space-between;
  box-shadow: 0px 6px 20px 0px rgba(0, 121, 253, 0.1) !important;
  background: #ffffff;
  .back_area {
    display: flex;
    width: 200px;
    height: 142px;
    img {
      width: 22px;
      height: 40px;
      margin-top: 60px;
      margin-right: 26px;
    }
    p {
      width: 75px;
      height: 36px;
      font-size: 36px;
      line-height: 36px;
      font-family: Microsoft YaHei, Microsoft YaHei-Regular;
      font-weight: 400;
      text-align: left;
      color: #007afd;
      margin-top: 60px;
    }
  }
  .page_title {
    width: 240px;
    height: 60px;
    line-height: 60px;
    font-size: 60px;
    font-family: Microsoft YaHei, Microsoft YaHei-Bold;
    font-weight: 700;
    text-align: left;
    color: #007afd;
    margin-top: 46px;
  }
  .to_home_area {
    display: flex;
    width: 149px;
    height: 142px;
    font-size: 36px;
    img {
      width: 50px;
      height: 47px;
      margin-top: 49px;
      margin-right: 27px;
    }
    p {
      width: 72px;
      height: 36px;
      line-height: 36px;
      font-size: 36px;
      font-family: Microsoft YaHei, Microsoft YaHei-Regular;
      font-weight: 400;
      text-align: left;
      color: #007afd;
      margin-top: 58px;
    }
  }
}
.content_area {
  display: flex;
  padding-bottom: 86px;
  padding-right: 50px;

  .menu_area {
    position: fixed;
    width: 283px;
    height: 452px;
    margin-top: 226px;
    // margin-right: 39px;
    .menu_item {
      width: 283px;
      height: 100px;
      display: flex;
      margin-bottom: 13px;
      border-radius: 0px 50px 50px 0px;
      box-shadow: 0px 0px 41.71px 0px #e5e5e5;
      color: #32518a;
      img {
        width: 54px;
        height: 54px;
        margin-top: 23px;
        margin-right: 23px;
        margin-left: 36px;
      }
      div {
        width: 145px;
        height: 24px;
        line-height: 24px;
        font-size: 24px;
        font-weight: 700;
        text-align: left;
        font-family: Microsoft YaHei Bold, Microsoft YaHei Bold-Bold;
        font-weight: 700;
        margin-top: 41px;
      }
    }
  }
}

.active {
  background: #007afd;
  color: #ffffff !important;
}

//过渡效果
.fade_slide-leave-active {
  will-change: transform;
  backface-visibility: hidden;
  position: absolute;
}
.fade_slide-enter-active{
  will-change: transform;
  backface-visibility: hidden;
}
.fade_slide-enter-active {
  transition: all 1s ease .5s;
}
.fade_slide-leave-active {
  transition: all .5s ease;
}
.fade_slide-enter-from {
  transform: translateX(10%);
  opacity: 0;
}
.fade_slide-leave-to {
  transform: translateX(10%);
  opacity: 0;
}
</style>
